package com.ts.animal.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import com.ts.common.service.IWaterCodeService;
import com.ts.common.utils.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ts.animal.domain.RfidLabelImportDO;
import com.ts.animal.service.RfidLabelImportService;
import com.ts.common.service.ExportExcelSevice;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 耳标录入表
 *
 * @author bobby
 * @email bobby@126.com
 * @date 2023-01-04 17:15:52
 */

@Controller
@RequestMapping("/animal/rfidLabelImport")
public class RfidLabelImportController {
	@Autowired
	private RfidLabelImportService rfidLabelImportService;

	@GetMapping()
	@RequiresPermissions("animal:rfidLabelImport:rfidLabelImport")
	String RfidLabelImport(){
	    return "animal/rfidLabelImport/rfidLabelImport";
	}

	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("animal:rfidLabelImport:rfidLabelImport")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
		PageUtils pageUtils = new PageInfos(params) {
			public List inject(Map params) {
				return rfidLabelImportService.list(params);
			}
		}.query().lowerUnderscore();
		pageUtils.setExData(CaseFormatUtil.lowerUnderscore(rfidLabelImportService.importLabelSum(params)));
		return pageUtils;
	}

	/**
	 * 批量删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("animal:rfidLabelImport:batchRemove")
	public Result remove(@RequestParam("ids[]") Integer[] ids){
		Result result = Result.ok();
		rfidLabelImportService.batchRemove(result,ids);
		return result;
	}


	/**
	 * 导入
	 */
	@PostMapping("batchImportLabel")
	@ResponseBody
	@RequiresPermissions("animal:rfidLabelImport:import")
	public Result batchImportLabel(MultipartFile file) {
		Result result;
		try {
			result = rfidLabelImportService.batchImportLabel(file);
		} catch (Exception e) {
			e.printStackTrace();
			result = Result.error("导入失败");
		}
		return result;
	}
}
